package com.restaurant.application.root.commonui.data;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;

import java.util.List;
import java.util.stream.Collectors;

public class ShowPage implements PickableBean {

    public static final String FN_NAME = "name";
    public static final String FN_EDITPATH = "editPath";
    public static final String FN_BACKPATH = "backPath";
    public static final String FN_ACCEPTPATH = "acceptPath";
    public static final String FN_COMMITPATH = "commitPath";
    public static final String FN_FIELDS = "fields";

    public static final List<String> FIELD_NAMES = Lists.newArrayList(
            FN_NAME,
            FN_EDITPATH,
            FN_BACKPATH,
            FN_ACCEPTPATH,
            FN_COMMITPATH,
            FN_FIELDS);

    private String name;
    private String editPath;
    private String backPath;
    private String acceptPath;
    private String commitPath;
    private List<ShowValue> fields;

    public ShowPage(String name, String editPath, String backPath, String acceptPath, String commitPath, List<ShowValue> fields) {
        setName(name);
        setEditPath(editPath);
        setBackPath(backPath);
        setAcceptPath(acceptPath);
        setCommitPath(commitPath);
        setFields(fields);
    }

    public ShowPage() {
    }

    public ShowPage duplicate() {
        ShowPage result = new ShowPage();
        result.name = this.name;
        result.editPath = this.editPath;
        result.backPath = this.backPath;
        result.acceptPath = this.acceptPath;
        result.commitPath = this.commitPath;
        result.fields = this.fields == null ? null : this.fields.stream().map(e2 -> e2 == null ? null : e2.duplicate()).collect(Collectors.toList());
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public String getName() {
        return name;
    }

    public void setName(String value) {
        this.name = value;
    }

    public ShowPage withName(String value) {
        setName(value);
        return this;
    }

    public ShowPage withName(String value, String defaultValue) {
        setName(value == null ? defaultValue : value);
        return this;
    }

    public String getEditPath() {
        return editPath;
    }

    public void setEditPath(String value) {
        this.editPath = value;
    }

    public ShowPage withEditPath(String value) {
        setEditPath(value);
        return this;
    }

    public ShowPage withEditPath(String value, String defaultValue) {
        setEditPath(value == null ? defaultValue : value);
        return this;
    }

    public String getBackPath() {
        return backPath;
    }

    public void setBackPath(String value) {
        this.backPath = value;
    }

    public ShowPage withBackPath(String value) {
        setBackPath(value);
        return this;
    }

    public ShowPage withBackPath(String value, String defaultValue) {
        setBackPath(value == null ? defaultValue : value);
        return this;
    }

    public String getAcceptPath() {
        return acceptPath;
    }

    public void setAcceptPath(String value) {
        this.acceptPath = value;
    }

    public ShowPage withAcceptPath(String value) {
        setAcceptPath(value);
        return this;
    }

    public ShowPage withAcceptPath(String value, String defaultValue) {
        setAcceptPath(value == null ? defaultValue : value);
        return this;
    }

    public String getCommitPath() {
        return commitPath;
    }

    public void setCommitPath(String value) {
        this.commitPath = value;
    }

    public ShowPage withCommitPath(String value) {
        setCommitPath(value);
        return this;
    }

    public ShowPage withCommitPath(String value, String defaultValue) {
        setCommitPath(value == null ? defaultValue : value);
        return this;
    }

    public List<ShowValue> getFields() {
        if (fields == null) {
            fields = Lists.newArrayList();
        }
        return fields;
    }

    public void setFields(List<ShowValue> value) {
        this.fields = value;
    }

    public ShowPage withFields(List<ShowValue> value) {
        setFields(value);
        return this;
    }

    public ShowPage withFields(List<ShowValue> value, List<ShowValue> defaultValue) {
        setFields(value == null ? defaultValue : value);
        return this;
    }

    public ShowPage addFields(ShowValue value) {
        if (fields == null) {
            fields = Lists.newArrayList();
        }
        this.fields.add(value);
        return this;
    }

    public Object getValueOf(String name) {
        switch (name) {
            case "name":
                return getName();
            case "editPath":
                return getEditPath();
            case "backPath":
                return getBackPath();
            case "acceptPath":
                return getAcceptPath();
            case "commitPath":
                return getCommitPath();
            case "fields":
                return getFields();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof ShowPage)) return false;
        return signature().equals(((ShowPage) o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean ShowPage has no signature defined, no hash code or equals possible.");
    }
}
